package io.renren.modules.region.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import io.renren.modules.region.entity.TCountryEntity;
import io.renren.modules.region.entity.TResidentEntity;
import io.renren.modules.region.entity.vo.CountryVO;
import io.renren.modules.region.entity.vo.ResidentVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 居民管理
 *
 * @author lhb
 * @date 2023-05-24 11:51:23
 */
@Mapper
public interface TResidentDao extends BaseMapper<TResidentEntity> {

    //    @Select("SELECT td.*, tu.username as creatorName FROM t_device td LEFT JOIN tb_user tu ON td.creator = tu.user_id WHERE td.`status` = 1")
    @Select("SELECT tt.*, tc.province as province, tc.city as city, tc.county as county, tc.address as address, tc.name as country_name FROM t_resident tt LEFT JOIN t_country tc ON tt.country_id = tc.id WHERE tt.is_delete=0 ")
    List<ResidentVO> queryResidents();

    @Select("SELECT tt.*, tc.province as province, tc.city as city, tc.county as county, tc.address as address, tc.name as country_name FROM t_resident tt LEFT JOIN t_country tc ON tt.country_id = tc.id WHERE tt.is_delete=0 AND (tt.`name` LIKE #{key} OR tt.`mobile` LIKE #{key} OR tc.`name` LIKE #{key})")
    List<ResidentVO> queryDevicesByKeySearch(@Param("key") String key);

    ResidentVO queryResidentById(@Param("id") String id);

    boolean deleteResidentById(@Param("ids") List<String> ids);
}
